package org.dragonnova.business.model;

/**
 * 分页
 */
public class Pager {
	// 1.当前页(currentPage)
	private int currentPage;
	// 2.每页数量(pageSize)
	private int pageSize;
	// 3.总页数(totalPage)
	private int totalPage;
	// 6.是否有上一页(hasPrePage)
	private boolean hasPrePage;
	// 7.是否有下一页(hasNextPage)
	private boolean hasNextPage;

	// 设置起始点，需要每页显示多少，当前页
	public int getFirstIndex() {
		return (currentPage - 1) * pageSize;
	}

    //设置是否有上一页，需要当前页  
    public  boolean getHasPrePage( ) {  
        return currentPage == 1 ? false : true;  
    }  
      
    //设置是否有下一个，需要总页数和当前页  
    public  boolean getHasNextPage() {  
        return currentPage >= totalPage || totalPage == 0 ? false : true;  
    }  
    /**
     * //设置总页数,需要总记录数
     * @param totalCount
     */
    public  void setTotalPage(int totalCount) {  
         totalPage = 0;  
        if(totalCount % pageSize == 0) {  
            totalPage = totalCount / pageSize;  
        } else {  
            totalPage = totalCount / pageSize + 1;  
        }  
    }  
    
	public Pager(int pageSize, int currentPage) {
		this.pageSize = pageSize;
		this.currentPage = currentPage;
	}

	// 构造函数，默认
	public Pager() {
		super();
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public boolean isHasPrePage() {
		return hasPrePage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

    //设置是否有上一页，需要当前页  
    public static boolean getHasPrePage(int currentPage) {  
        return currentPage == 1 ? false : true;  
    }  
      
    //设置是否有下一个，需要总页数和当前页  
    public static boolean getHasNextPage(int totalPage, int currentPage) {  
        return currentPage == totalPage || totalPage == 0 ? false : true;  
    }  
}
